#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Stu Stu;
struct Stu {
    char name[20];
    int age;
};
int cmp_int(const void* p1, const void* p2)
{
    if (*(int*)p1 > *(int*)p2)
        return 1;
    else if (*(int*)p1 < *(int*)p2)
        return -1;
    else
        return 0;
}
int cmp_stu(const void* p1, const void* p2)
{
    return (*(Stu*)p1).age - (*(Stu*)p2).age;
}
int cmp_stu_char(const void* p1, const void* p2)
{
    return strcmp((*(Stu*)p1).name, (*(Stu*)p2).name);
}
void Print(int* arr, int sz)
{
    for (int i = 0; i < sz; i++)
    {
        printf("%d ", arr[i]);
    }
}
void test1()
{
    int arr[] = { 45,12,56,89,15 };
    int sz = sizeof(arr) / sizeof(arr[0]);
    qsort(arr, sz, sizeof(arr[0]), cmp_int);
    Print(arr, sz);
}
void test2()
{
    Stu s[] = { {.age = 22,.name = "lisi"} ,
        {.age = 54,.name = "wangwu"},
        {.age = 12,.name = "zhaoliu"} };
    int sz = sizeof(s) / sizeof(s[0]);
    qsort(s, sz, sizeof(s[0]), cmp_stu);
    for (int i = 0; i < sz; i++)
    {
        printf("%s ", s[i].name);
        printf("%d\n", s[i].age);
    }
}
void test3()
{
    Stu s[] = { {.name = "lisi",.age = 22},
        {.name = "wangwu",.age = 25},
        {.name = "zhaoliu",.age = 24} };
    int sz = sizeof(s) / sizeof(s[0]);
    qsort(s, sz, sizeof(s[0]), cmp_stu_char);
    for (int i = 0; i < sz; i++)
    {
        printf("%s ", s[i].name);
        printf("%d\n", s[i].age);
    }
}
int main()
{
    /*test1();*/
    /*test2();*/
    test3();
    return 0;
}